﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using BusinessObjects;

namespace PracticeSimple.Models
{
    public class EncounterModel
    {
        public Encounter encounter { get; set; }
        public Patient patient {get; set;}
        public List<Vital> vitals { get; set; }

        public HtmlString renderVital(Vital v)
        {
            if (v.ParentVitalID.HasValue)
            {
                return new HtmlString("");
            }

            string markup = "<li>";

            List<Vital> childVitals = this.vitals.Where(x => x.ParentVitalID == v.VitalID).ToList();

            if (childVitals.Count > 0)
            {
                markup = markup + String.Format("{0}</li><ul>", v.VitalName);

                foreach(Vital cv in childVitals)
                {
                    markup = markup + RenderInput(cv);
                }
                
                markup = markup + "</ul>";
            }
            else
            {
                markup = markup + RenderInput(v) + "</li>";
            }

            return new HtmlString(markup);
        }

        private string RenderInput(Vital v)
        {
            string markup = "";

            switch (v.InputTypeID)
            {

                case (int)MasterType.Textbox:
                    markup = String.Format("<label for='tb{1}'>{0}</label><input type='text' data-vitalid='{2}' id='tb{1}' name='tb{1}' />", v.VitalName, v.VitalName.Replace(" ", ""),  v.VitalID);
                    break;

                default:
                    markup = "Input type not implemented";
                    break;
            }

            return markup;
        }


    }
}